package com.gzk.oeno.business.compare;

import java.util.Comparator;

import com.gzk.oeno.business.recompense.Recompense;
import com.gzk.oeno.tech.set.IdPair;

public class RecompenseClassComparator implements Comparator<IdPair<Recompense, Integer>>{

	private final RecompenseComparator recComparator = new RecompenseComparator();
	
	@Override
	public int compare(IdPair<Recompense, Integer> o1, IdPair<Recompense, Integer> o2) {
		if (o1 == null && o2 == null)
			return 0;
		if (o1 == null)
			return 1;
		if (o2 == null)
			return -1;
		if (o1.getSecond() == null && o2.getSecond() == null)
			return recComparator.compare(o1.getFirst(), o2.getFirst());
		if (o1.getSecond() == null)
			return 1;
		if (o2.getSecond() == null)
			return -1;
		
		int rangComp = o1.getSecond().compareTo(o2.getSecond());
		if (rangComp == 0){
			return recComparator.compare(o1.getFirst(), o2.getFirst());
		}
		return rangComp;
	}

}
